package tasoloikka;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class Player {

  private Gun gun;
  
  //Objektin sijainti & koko
  private int positionX;
  private int positionY;
  private int prevPositionX;
  private int prevPositionY;
  private int lastMovementRangeX;
  private int lastMovementRangeY;
  private int width;
  private int height;
  private int jump;
  private boolean allowJump = true;

  public Player(Gun gun) {
    this.positionX = 300;
    this.positionY = 100;
    this.prevPositionX = 300;
    this.prevPositionY = 100;
    this.width = 16;
    this.height = 32;
    
    this.gun = gun;
  }

  public void paint(Graphics gbi) {
    gbi.setColor(Color.green);
    gbi.drawRect(positionX, positionY, width, height);
    gbi.setColor(Color.white);
    gbi.drawString("Player(" + positionX + "," + positionY + "),(" + prevPositionX + "," + prevPositionY + ") " + allowJump, 10, 10);
    gbi.drawString("BlockPos(" + positionX/16 + "," + positionY/16 + ")", 10, 25);
  }

  public void startJump(int jumpSpeed) {
    jump = jumpSpeed;
    setPositionY(-jump);
  }

  public void jumpInProgress() {
    setPositionY(-jump);
    jump--;
  }

  //Setterit
  //Setterit
  //Setterit
  public void setPositionX(int x) {
    this.lastMovementRangeX = x;
    this.prevPositionX = positionX;
    this.positionX += x;
  }

  public void setPositionY(int y) {
    this.lastMovementRangeY = y;
    this.prevPositionY = positionY;
    this.positionY += y;
  }
  
  public void setPrevPositionX() {
    this.prevPositionX = positionX;
  }

  public void setPrevPositionY() {
    this.prevPositionY = positionY;
  }

  public void setX(int x) {
    this.prevPositionX = positionX;
    this.positionX = x;
  }

  public void setY(int y) {
    this.prevPositionY = positionY;
    this.positionY = y;
  }

  public void setAllowJump(boolean allow) {
    if (allow) {
      allowJump = true;
    } else {
      allowJump = false;
    }
  }
  
  public void setJump(int j){
    jump = j;
  }

  //Getterit
  //Getterit
  //Getterit
  public Rectangle getRectangle() {
    return (new Rectangle(positionX, positionY, width, height));
  }

  public int getPositionX() {
    return positionX;
  }

  public int getPositionY() {
    return positionY;
  }

  public int getWidth() {
    return width;
  }

  public int getHeight() {
    return height;
  }

  public int getPrevPositionX() {
    return prevPositionX;
  }

  public int getPrevPositionY() {
    return prevPositionY;
  }

  public int getJump() {
    return jump;
  }

  public boolean getAllowJump() {
    return allowJump;
  }
  
  public int getLastMovementX(){
    return lastMovementRangeX;
  }
  
  public int getLastMovementY(){
    return lastMovementRangeY;
  }
  
  
}
